package com.zxj.friend.controller.user;


import com.zxj.common.core.contains.HttpConstants;
import com.zxj.common.core.controller.BaseController;
import com.zxj.common.core.domain.R;
import com.zxj.common.core.domain.vo.PageVO;
import com.zxj.common.core.utils.ThreadLocalUtil;
import com.zxj.friend.aspect.CheckUserStatus;
import com.zxj.friend.domain.exam.dto.ExamQueryPageDTO;
import com.zxj.friend.domain.exam.vo.ExamVO;
import com.zxj.friend.domain.user.dto.UserEnterExamDTO;
import com.zxj.friend.service.user.IUserExamService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.models.security.SecurityScheme;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 竞赛报名表 前端控制器
 * </p>
 *
 * @author zxj2022
 * @since 2025-01-08
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/user/exam")
@Tag(name = "用户竞赛关系相关接口", description = "用户竞赛关系相关接口")
public class UserExamController extends BaseController {
    private final IUserExamService userExamService;


    @PostMapping("/enter")
    @Operation(summary = "用户报名竞赛", description = "用户报名竞赛")
    @Parameters({
            @Parameter(name = HttpConstants.AUTHENTICATION, description = "用户token", required = true, in = ParameterIn.HEADER, schema = @Schema(type = "string")),
            @Parameter(name = "userEnterExamDTO", description = "用户报名竞赛DTO", required = true, in = ParameterIn.DEFAULT, schema = @Schema(implementation = UserEnterExamDTO.class))
    })
    @CheckUserStatus // 检查用户状态, 进行拉黑限制
    public R<Void> enter(@RequestBody UserEnterExamDTO userEnterExamDTO) {
        log.info("用户报名竞赛请求, 用户ID: {}; 竞赛ID: {}", ThreadLocalUtil.getUserId(), userEnterExamDTO.getExamId());
        return toR(userExamService.enter(userEnterExamDTO.getExamId()));
    }

    @GetMapping("/list")
    @Operation(summary = "获取用户报名竞赛列表", description = "获取用户报名竞赛列表")
    @Parameters({
            @Parameter(name = HttpConstants.AUTHENTICATION, description = "用户token", required = true, in = ParameterIn.HEADER, schema = @Schema(type = "string")),
    })
    public R<PageVO<ExamVO>> list(ExamQueryPageDTO examQueryPageDTO) {
        log.info("获取用户报名竞赛列表请求, 请求参数：{}", examQueryPageDTO);
        return R.ok(userExamService.pageList(examQueryPageDTO));
    }

}
